package com.example.basecore.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author ycd0075
 * @date 2024-01-25 22:28
 */
@Data
@NoArgsConstructor
public class PageQuery implements Serializable {

    private int pageIndex;
    private int pageSize;

    /**
     * 获取偏移量, 从0开始
     *
     * @return
     */
    public int getOffset() {
        return (pageIndex - 1) * pageSize;
    }

    /**
     * 获取限制的偏移量
     *
     * @return
     */
    public int getLimitOffset() {
        return  pageSize;
    }

    public PageQuery(int pageIndex, int pageSize){
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
    }

    public static PageQuery of(int pageIndex, int pageSize){
        return new PageQuery(pageIndex, pageSize);
    }
}
